package com.yj.rselasticsearch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yj.common.core.domain.AjaxResult;
import com.yj.common.core.domain.entity.WarningInfo;
import com.yj.common.utils.StringUtils;
import com.yj.rselasticsearch.domain.dto.WarningInfoDto;
import com.yj.rselasticsearch.mapper.WarningInfoMapper;
import com.yj.rselasticsearch.service.WarningInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 告警信息
 */
@Service
public class WarningInfoServiceImpl extends ServiceImpl<WarningInfoMapper, WarningInfo> implements WarningInfoService {

    @Resource
    private WarningInfoMapper warningInfoMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return warningInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(WarningInfo record) {
        return warningInfoMapper.insert(record);
    }

    @Override
    public int insertSelective(WarningInfo record) {
        return warningInfoMapper.insertSelective(record);
    }

    @Override
    public WarningInfo selectByPrimaryKey(Integer id) {
        return warningInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(WarningInfo record) {
        return warningInfoMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(WarningInfo record) {
        return warningInfoMapper.updateByPrimaryKey(record);
    }

    @Override
    public AjaxResult queryAllData(WarningInfoDto warningInfoDto) {
        IPage<WarningInfo> warningInfoIPage = new Page<>(warningInfoDto.getPageIndex(), warningInfoDto.getPageSize());
        warningInfoIPage = page(warningInfoIPage, new LambdaQueryWrapper<WarningInfo>().
                like(!StringUtils.isEmpty(warningInfoDto.getQuestion()), WarningInfo::getQuestion, warningInfoDto.getQuestion()).
                like(!StringUtils.isEmpty(warningInfoDto.getWarningLeve()), WarningInfo::getWarningLeve, warningInfoDto.getWarningLeve()).
                orderByDesc(WarningInfo::getCreateTime));
        return AjaxResult.success(warningInfoIPage);
    }

}
